home *** CD-ROM | disk | FTP | other *** search
/ Freelog 15 / FREELOG 15.ISO / WebMaster / Perl / PERL5106.ZIP / perl5 / Lib / Config.pm < prev    next >
Encoding:
Perl POD Document  |  1996-02-28  |  6.2 KB  |  358 lines

  1. package Config;
  2. require Exporter;
  3. @ISA = (Exporter);
  4. @EXPORT = qw(%Config);
  5.  
  6. $] == 5.001 or die sprintf
  7.     "Perl lib version (5.001) doesn't match executable version (%.3f)\n", $];
  8.  
  9.  
  10. #### Hard coded for Win32 - WYT 1995-10-23
  11.  
  12. =head1 NAME
  13.  
  14. Config - access Perl configuration option
  15.  
  16. =head1 SYNOPSIS
  17.  
  18.     use Config;
  19.     if ($Config{'cc'} =~ /gcc/) {
  20.     print "built by gcc\n";
  21.     } 
  22.  
  23. =head1 DESCRIPTION
  24.  
  25. The Config module contains everything that was available to the
  26. C<Configure> program at Perl build time.  Shell variables from
  27. F<config.sh> are stored in the readonly-variable C<%Config>, indexed by
  28. their names.
  29.  
  30. =head1 EXAMPLE
  31.  
  32. Here's a more sophisticated example of using %Config:
  33.  
  34.     use Config;
  35.  
  36.     defined $Config{sig_name} || die "No sigs?";
  37.     foreach $name (split(' ', $Config{sig_name})) {
  38.     $signo{$name} = $i;
  39.     $signame[$i] = $name;
  40.     $i++;
  41.     }   
  42.  
  43.     print "signal #17 = $signame[17]\n";
  44.     if ($signo{ALRM}) { 
  45.     print "SIGALRM is $signo{ALRM}\n";
  46.     }   
  47.  
  48. =head1 NOTE
  49.  
  50. This module contains a good example of how to make a variable
  51. readonly to those outside of it.  
  52.  
  53. =cut
  54.  
  55. $config_sh=<<'!END!OF!CONFIG!';
  56. archlib=''
  57. ccflags=''
  58. cppflags=''
  59. dynamic_ext=''
  60. extensions=''
  61. intsize='4'
  62. libpth=''
  63. osname='MSWin32'
  64. osvers='3.51'
  65. sharpbang=''
  66. shsharp=''
  67. sig_name=''
  68. so='dll'
  69. startsh=''
  70. static_ext=' '
  71. Author=''
  72. CONFIG='true'
  73. Date='$Date'
  74. Header=''
  75. Id='$Id'
  76. Locker=''
  77. Log='$Log'
  78. Mcc='Mcc'
  79. PATCHLEVEL='1'
  80. RCSfile='$RCSfile'
  81. Revision='$Revision'
  82. Source=''
  83. State=''
  84. afs='false'
  85. alignbytes='4'
  86. aphostname=''
  87. archlibexp=
  88. archname='i386-win32'
  89. awk='awk'
  90. baserev='5.0'
  91. bash=''
  92. bin=''
  93. binexp=''
  94. bison=''
  95. byacc='byacc'
  96. byteorder='1234'
  97. c=''
  98. castflags='0'
  99. cat='type'
  100. cc='cl'
  101. cccdlflags=''
  102. ccdlflags=''
  103. cf_by=''
  104. cf_time=''
  105. chgrp=''
  106. chmod=''
  107. chown=''
  108. clocktype=''
  109. comm='comm'
  110. compress=''
  111. contains=''
  112. cp='copy'
  113. cpio=''
  114. cpp='cl /E'
  115. cpp_stuff=''
  116. cpplast=''
  117. cppminus=''
  118. cpprun='cl /E'
  119. cppstdin='cl /E'
  120. cryptlib=''
  121. csh='cmd'
  122. date='date'
  123. db_hashtype='u_int32_t'
  124. db_prefixtype='size_t'
  125. defvoidused='15'
  126. direntrytype='struct dirent'
  127. dlext='pll'
  128. dlsrc='dl_win32.xs'
  129. echo='echo'
  130. egrep=''
  131. emacs=''
  132. eunicefix=':'
  133. expr=''
  134. find=''
  135. flex=''
  136. fpostype='fpos_t'
  137. freetype='void'
  138. full_csh=''
  139. full_sed=''
  140. gcc=''
  141. gccversion=''
  142. gidtype='gid_t'
  143. glibpth=''
  144. grep=''
  145. groupcat=''
  146. groupstype='gid_t'
  147. h_fcntl='false'
  148. h_sysfile=''
  149. hint='recommended'
  150. hostcat=''
  151. huge=''
  152. incpath=''
  153. inews=''
  154. installarchlib=''
  155. installbin=''
  156. installman1dir=''
  157. installman3dir=''
  158. installprivlib=''
  159. installscript=''
  160. installsitelib=''
  161. known_extensions=''
  162. ksh=''
  163. large=''
  164. ld='link32'
  165. lddlflags=''
  166. ldflags=''
  167. less=''
  168. libc=''
  169. libs=''
  170. libswanted=''
  171. line=''
  172. lint=''
  173. lkflags=''
  174. ln=''
  175. lns=''
  176. lp=''
  177. lpr=''
  178. ls='dir'
  179. lseektype='off_t'
  180. mail=''
  181. mailx=''
  182. make='nmake'
  183. mallocobj=''
  184. mallocsrc=''
  185. malloctype='void *'
  186. man1dir=''
  187. man1direxp=''
  188. man1ext=''
  189. man3dir=''
  190. man3direxp=''
  191. man3ext=''
  192. medium=''
  193. mips=''
  194. mips_type=''
  195. mkdir='mkdir'
  196. models='none'
  197. modetype='mode_t'
  198. more=''
  199. mv='rename'
  200. myarchname='i386-win32'
  201. mydomain=''
  202. myhostname=''
  203. myuname=''
  204. n=''
  205. nm_opt=''
  206. nroff=''
  207. optimize=''
  208. orderlib='false'
  209. package='perl5'
  210. passcat=''
  211. patchlevel='1'
  212. perl='perl'
  213. pg=''
  214. phostname='hostname'
  215. plibpth=''
  216. pmake=''
  217. pr=''
  218. prefix=''
  219. prefixexp=''
  220. privlib=''
  221. privlibexp=''
  222. prototype='define'
  223. randbits='31'
  224. ranlib=':'
  225. rm='del'
  226. rmail=''
  227. runnm='true'
  228. scriptdir=''
  229. scriptdirexp=''
  230. sed=''
  231. selecttype='fd_set *'
  232. sendmail=''
  233. sh=''
  234. shar=''
  235. shmattype='char *'
  236. shrpdir='none'
  237. signal_t='void'
  238. sitelib=''
  239. sitelibexp=''
  240. sizetype='size_t'
  241. sleep=''
  242. smail=''
  243. small=''
  244. sockethdr=''
  245. socketlib=''
  246. sort='sort'
  247. spackage='Perl5'
  248. spitshell='type'
  249. split=''
  250. ssizetype='ssize_t'
  251. stdchar='char'
  252. stdio_base='((fp)->_IO_read_base)'
  253. stdio_bufsiz='((fp)->_IO_read_end - (fp)->_IO_read_base)'
  254. stdio_cnt='((fp)->_IO_read_end - (fp)->_IO_read_ptr)'
  255. stdio_ptr='((fp)->_IO_read_ptr)'
  256. strings=''
  257. submit=''
  258. sysman=''
  259. tail=''
  260. tar=''
  261. tbl=''
  262. test='test'
  263. timeincl=''
  264. timetype='time_t'
  265. touch=''
  266. tr=''
  267. troff=''
  268. uidtype='uid_t'
  269. uname=''
  270. uniq=''
  271. usedl='define'
  272. usemymalloc='n'
  273. usenm='false'
  274. useposix='false'
  275. usevfork='false'
  276. usrinc=''
  277. uuname=''
  278. vi=''
  279. voidflags='15'
  280. xlibpth=''
  281. zcat=''
  282. !END!OF!CONFIG!
  283.  
  284.  
  285. tie %Config, Config;
  286. sub TIEHASH { bless {} }
  287. sub FETCH { 
  288.     # check for cached value (which maybe undef so we use exists not defined)
  289.     return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});
  290.  
  291.     my($value); # search for the item in the big $config_sh string
  292.     return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m);
  293.  
  294.     $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}".
  295.     $_[0]->{$_[1]} = $value; # cache it
  296.     return $value;
  297. }
  298.  
  299. sub FIRSTKEY {
  300.     $prevpos = 0;
  301.     my $key;
  302.     ($key) = $config_sh =~ m/^(.*)=/;
  303.     $key;
  304. }
  305.  
  306. sub NEXTKEY {
  307.     my ($pos, $len);
  308.     $pos = $prevpos;
  309.     $pos = index( $config_sh, "\n", $pos) + 1;
  310.     $prevpos = $pos;
  311.     $len = index( $config_sh, "=", $pos) - $pos;
  312.     $len > 0 ? substr( $config_sh, $pos, $len) : undef;
  313. }
  314.  
  315. sub EXISTS{ 
  316.      exists($_[0]->{$_[1]})  or  $config_sh =~ m/^$_[1]=/m; 
  317. }
  318.  
  319. sub readonly { die "\%Config::Config is read-only\n" }
  320.  
  321. sub myconfig {
  322.     my($output);
  323.     
  324.     $output = <<'END';
  325. Summary of my $package (patchlevel $PATCHLEVEL) configuration:
  326.   Platform:
  327.     osname=$osname, osver=$osvers, archname=$archname
  328.     uname='$myuname'
  329.     hint=$hint
  330.   Compiler:
  331.     cc='$cc', optimize='$optimize'
  332.     cppflags='$cppflags'
  333.     ccflags ='$ccflags'
  334.     ldflags ='$ldflags'
  335.     stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork
  336.     voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg
  337.     intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits
  338.   Libraries:
  339.     so=$so
  340.     libpth=$libpth
  341.     libs=$libs
  342.     libc=$libc
  343.   Dynamic Linking:
  344.     dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun
  345.     cccdlflags='$cccdlflags', ccdlflags='$ccdlflags', lddlflags='$lddlflags'
  346.  
  347. END
  348.     $output =~ s/\$(\w+)/$Config{$1}/ge;
  349.     $output;
  350. }
  351.  
  352. sub STORE { &readonly }
  353. sub DELETE{ &readonly }
  354. sub CLEAR { &readonly }
  355.  
  356.  
  357. 1;
  358.